package throwsthrowDemo;

public class Test1 {
    public static void main(String[] args) {
        int[] arr = null;

        try {
            int max = getMax(arr);
        } catch (NullPointerException e) {
            System.out.println("空指针");
        }
         catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("越界");
        }

        System.out.println("========================");
    }

    public static int getMax(int[] arr) {
//        if (arr == null) {
//            throw new NullPointerException();
//        }
//
//        if (arr.length == 0) {
//            throw new ArrayIndexOutOfBoundsException();
//        }
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        return max;
    }
}
